class Watcher {
  constructor(vm, key, cb) {
    this.vm = vm;
    this.key = key;
    this.cb = cb;

    Dep.target = this;

    this.oldValue = vm[key]; // 这里自动把自己加入到了dep依赖中

    Dep.target = null;
  }

  update() {
    const newValue = this.vm[this.key];
    if (newValue !== this.oldValue) {
      this.cb(newValue, this.oldValue);
      this.oldValue = newValue;
    }
  }
}